﻿using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.NPCs.Enemies.Biomesa.Jungle
{
    public class Lizard : ModNPC
    {
        public override void SetStaticDefaults()
        {
            Main.npcFrameCount[NPC.type] = 6;
        }

        public override void SetDefaults()
        {
            NPC.lifeMax = 30;
            NPC.damage = 18;
            NPC.defense = 9;
            NPC.knockBackResist = 0.6f;
            NPC.width = 42;
            NPC.height = 22;
            AnimationType = 102;
            NPC.aiStyle = 26;
            NPC.npcSlots = 15f;
            NPC.HitSound = SoundID.NPCHit1;
            NPC.DeathSound = SoundID.NPCDeath1;
            NPC.value = Item.buyPrice(0, 0, 0, 0);
        }
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Jungle,
                new FlavorTextBestiaryInfoElement("Mods.HardcoreGame.Bestiary.Lizard")
            ]);
        }
        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            if (spawnInfo.Player.ZoneJungle || spawnInfo.Player.ZoneDesert)
            {
                return 0.25f;
            }
            return 0f;
        }
        public override void HitEffect(NPC.HitInfo hit)
        {
            int num = 0;
            while (num < hit.Damage / (double)NPC.lifeMax * 50.0)
            {
                Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 0.8f);
                num++;
            }
            if (NPC.life <= 0)
            {
                var entitySource = NPC.GetSource_Death();
                Gore.NewGore(entitySource, NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_19").Type, 1f);
                Gore.NewGore(entitySource, NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_20").Type, 1f);               
            }
        }
    }
}
